<?php
class Merchant_Model_ProductHistory extends Zend_Db_Table_Abstract
{
	protected $_table;
	
	public function __construct(){
		$this->_table = new Merchant_Model_DbTable_ProductHistory();
	}
	
	public static function getInstance(){
		return new Merchant_Model_ProductHistory();
	}
	
	/**
	* 获得dbtable对象
	* @return Zend_Db_Table_Abstract
	*/
	public function getDbTable(){
		return $this->_table;
	}
	
	/**
	* 获得产品的日志信息
	* @param int $productId
	* @param int $page
	* @param int $pageSize
	* @return Zend_db_table_rowset
	*/
	public function getByProductId($productId,$page,$pageSize){
		
		if($page < 1) $page = 1;
		if($pageSize < 1) $pageSize = 1;
		$where = $this->_table->getAdapter()->quoteInto("product_id = ?",$productId);

		$row = $this->_table->fetchAll($where,' ph_add_time desc',$pageSize,($page-1)*$pageSize);
		return $row;
	}
	
	/**
	* 获取记录总数
	* @param $productId
	* @return int
	*/
	public function getCount($productId){
		$select = $this->_table->getAdapter()->select()->from($this->_table->info("name"),"count(*)")->where("product_id=?",$productId);
		$count = $this->_table->getAdapter()->fetchOne($select);
		return $count;
	}
}